package com.leetcode.algorithm.y22.m07;

import java.util.HashSet;
import java.util.Set;

/**
 * 73. 矩阵置零
 * 
 * https://leetcode.cn/problems/set-matrix-zeroes/
 * 
 * @author jie.deng
 *
 */
class Question0073Solution01 {

	public void setZeroes(int[][] matrix) {
		int rows = matrix.length;
		int cols = matrix[0].length;
		Set<Integer> zeroRowSet = new HashSet<>();
		Set<Integer> zeroColSet = new HashSet<>();
		for (int row = 0; row < rows; row++) {
			for (int col = 0; col < cols; col++) {
				if (matrix[row][col] == 0) {
					zeroRowSet.add(row);
					zeroColSet.add(col);
				}
			}
		}
		for (int row = 0; row < rows; row++) {
			for (int col = 0; col < cols; col++) {
				if (zeroRowSet.contains(row) || zeroColSet.contains(col)) {
					matrix[row][col] = 0;
				}
			}
		}
	}

}